package data;

import android.util.Log;

public class Coordinate {
	
public double longitude; 
public double latitude;
static double R = 6371; // km
static double PIx = 3.141592653589793;

public Coordinate(double longi, double lat){
	longitude=longi;
	latitude=lat;
}


public double distanceKM(Coordinate otherCoor)
{	
	double dLat = toRad(this.latitude-otherCoor.latitude);
	double dLon = toRad(this.longitude-otherCoor.longitude);
    double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + Math.cos(toRad(this.latitude)) * Math.cos(toRad(otherCoor.latitude)) * (Math.sin(dLon / 2) * Math.sin(dLon / 2));
    double angle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return angle* R;	
}

private double toRad(double val)
{
	return PIx*val/180;
}

public boolean equale(Coordinate anotherCoor)
{
	Log.d("this",Double.toString(this.latitude)+" "+Double.toString(this.longitude));
	Log.d("other",Double.toString(anotherCoor.latitude)+" "+Double.toString(anotherCoor.longitude));

	if((this.latitude==anotherCoor.latitude)&&(this.longitude==anotherCoor.longitude))
	{

		return true;

	}
	Log.d("false","false");
	return false;
	
}
}
